package com.miao.im.api;

import com.miao.im.common.ApiResult;
import com.miao.im.domain.UserDo;
import com.miao.im.dto.FriendReqDto;
import com.miao.im.dto.FriendRespDto;
import com.miao.im.service.friend.IFriendService;
import com.miao.im.support.WebSessionHolder;
import com.miao.im.support.exception.AuthenticationException;
import com.miao.im.support.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: miaoguoxin
 * @Date: 2021/4/11 20:21
 * @Description:
 */
@RestController
@RequestMapping("/friend")
public class FriendController {
    @Autowired
    private IFriendService friendService;

    @GetMapping("/minePage")
    public ApiResult<Page<List<FriendRespDto>>> getMinePage(Integer pageNum ,Integer pageSize){
        Long userId = WebSessionHolder.getUserIdNotNull();
        Page<List<FriendRespDto>> friendPage = friendService.getMyFriendPage(userId, pageNum, pageSize);
        return ApiResult.ok(friendPage);
    }

    @PostMapping("/add")
    public ApiResult<?> add(@RequestBody FriendReqDto reqDto){
        Long userId = WebSessionHolder.getUserIdNotNull();
        friendService.add(userId,reqDto.getUsername());
        return ApiResult.ok("");
    }
}
